import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';

class SearchSongItem extends StatelessWidget {
  final String title;
  final String artist;
  final String cover;
  final VoidCallback onTap;

  const SearchSongItem({
    super.key,
    required this.title,
    required this.artist,
    required this.cover,
    required this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return ListTile(
      leading: ClipRRect(
        borderRadius: BorderRadius.circular(8),
        child: CachedNetworkImage(
          imageUrl: cover.isNotEmpty ? cover : 'https://picsum.photos/200/300',
          width: 50,
          height: 50,
          fit: BoxFit.cover,
          placeholder: (context, url) => Container(
            width: 50,
            height: 50,
            color: Colors.grey[800],
          ),
          errorWidget: (context, url, error) =>
              Icon(Icons.music_note, color: Colors.grey[600]),
        ),
      ),
      title: Text(title, style: const TextStyle(color: Colors.white)),
      subtitle: Text(
        artist,
        style: const TextStyle(color: Colors.grey),
      ),
      trailing: const Icon(Icons.play_arrow, color: Colors.white),
      onTap: onTap,
      tileColor: Colors.black,
    );
  }
}